﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using ControlModule.Models;

namespace ControlModule.Daos
{
    public class QuestionDao
    {
        public static List<Question> LoadQuestionByLabworkId(int labworkId)
        {
            using (CmDbEntities db = new CmDbEntities())
                return (
                    from s in db.Question
                    from r in db.RelLabworkQuestion
                    where s.Id == r.QuestionId
                    where r.LabworkId == labworkId
                    select s).ToList();
        }
        public  static int GetRightAnswersCount(int labworkId, int userId)
        {
            using (CmDbEntities db = new CmDbEntities())
                return (
                           from q in db.RelQuestionAnswer
                           from a in db.RelLabworkUserQuestionAnswer
                           where a.LabworkId == labworkId
                           where a.UserId == userId
                           where q.AnswerId == a.AnswerId
                           where q.IsTrueAnswer == true
                           select q
                       ).ToList().Count;
        }
    }
}